import type { RespCommonDataType } from "@/service/api/common";
import {helper} from "@yaf/utils";
const { deepmerge } = helper;

export interface EnumEnvType {
  rootPath?: string,                // 根路由前缀
  staticPublicPath?: string,        // 静态资源公共路径
  apiDomain?: string,               // api地址
  apiResponseCode?: {
    apiSuccessCode?: string,        // 请求成功响应code
    errorCode?: string,             // 请求失败响应code
    noLoginCode?: string,           // 未登录的code
    noPermissionCode?: string,      // 未登录的code
    invalidParamCode?: string,      // 参数校验失败code
  },
  allowBrowser?: {
    name: string,
    minVersion: number
  }[],
  intl?: {
    lang?: string,                 // 语言
    timeZoneOffset?: number,       // 时区偏差, 单位分钟
  },
  app?: {
    title?: string,
    logo?: string,
    pure?:boolean,   // 是否不显示菜单
    comfyuiNotAuth?: boolean,    // 是否不认证comfyui接口
  },
  globalConfig?: RespCommonDataType.IGlobalConfig;
}

let EnumEnv: EnumEnvType = deepmerge<EnumEnvType>({
  rootPath: "/",                            // 根路由前缀
  staticPublicPath: "/static",              // 静态资源公共路径
  apiDomain: "",                            // api地址
  apiResponseCode: {
    apiSuccessCode: "200",                    // 请求成功响应code
    // apiSuccessCode: "0",                    // 请求成功响应code
    errorCode: "error",                       // 请求失败响应code
    noLoginCode: "401",                       // 未登录的code
    noPermissionCode: "403",                  // 没有权限的code
    invalidParamCode: "400",                  // 参数校验失败code
  },

  allowBrowser: [                            // 允许的浏览器类型和版本，如果不设置将不会检查
    { name: "chrome", minVersion: 0 },
    { name: "mozilla", minVersion: 0 },
    { name: "opera", minVersion: 0 },
    { name: "safari", minVersion: 0 },
    { name: "konqueror", minVersion: 0 },
  ],
  intl: {
    lang: 'zh',                 // 语言
    timeZoneOffset: 8 * 60,     // 时区偏差, 单位分钟
  },
  app: {
    // title: "秀才闻咖",
    title: "",
    logo: require("../img/logo.png"),
    pure: false,
    comfyuiNotAuth: false,
  },
}, window.ENV);

export const getEnv = () => EnumEnv;

export const setEnv = (env: EnumEnvType) => {
  EnumEnv = deepmerge(EnumEnv, env || {});
};

